import React, {useRef} from 'react';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import ProTable from '@ant-design/pro-table';
import { getSporadicList } from '../service';
import moment from 'moment';

const TableList = () => {
  const actionRef = useRef();

  const columns = [
    {
      title: '申请时间',
      dataIndex: 'createTime',
      render: (text) => {
        return text !== '-' ? moment(text).format('YYYY-MM-DD') : ''
      },
    },
    {
      title: '申请人',
      dataIndex: 'oprationName',
    },
    {
      title: '申请人工号',
      dataIndex: 'oprationId',
    },
    {
      title: '加班名称',
      dataIndex: 'overworkName',
    },
    {
      title: '加班人员',
      dataIndex: 'userName',
    },
    {
      title: '加班时间(月份)',
      dataIndex: 'overworkTime',
      render: (text) => {
        return text !== '-' ? moment(text).format('YYYY-MM') : '';
      },
    },
    {
      title: '加班时长',
      dataIndex: 'longOverwork',
      render: (text) => {
        return text !== '-' ? text + `小时` : '';
      },
    },
    {
      title: '加班说明',
      dataIndex: 'remark',
      ellipsis:true,
      width: 200
    },
    {
      title: '状态',
      dataIndex: 'status',
      valueEnum: {
        0: {text: '待发起', status: 'Default'},
        1: {text: '审批中', status: 'Processing'},
        2: {text: '审批通过', status: 'Success'},
        3: {text: '审批拒绝', status: 'Warning'},
      },
    },
  ];

  return (
    <PageHeaderWrapper>
      <ProTable
        actionRef={actionRef}
        search={false}
        rowKey="id"
        request={(params) => getSporadicList(params)}
        columns={columns}
      />
    </PageHeaderWrapper>
  )
};
export default (TableList);
